{{#extends @html/widgets/node_widget.html}}
{{:widget_div_name}}items{{/:widget_div_name}}

{{:widget_body}}
	{{!connect "screen/widgets/wg-items.css"}}
	{{?widget.content.items}}
	
	{{?widget.content.ftype == "fimage"}}
		<ul class="list-images-">
		{{!for widget.content.items as="items" do=@:items}}
		</ul>
	{{?:widget.content.ftype == "ffile"}}
		<ul class="list-files-">
		{{!for widget.content.items as="items" do=@:items}}
		</ul>
	{{?:}}
		{{!for widget.content.items as="items" do=@:items}}
	{{/?}}
	{{?:}}
		<div class="content">
			<p>Записей пока нет</p>
		</div>
	{{/?}}
{{/:widget_body}}

{{:widget_title}}{{?widget.title}}{{widget.title}}{{?:}}Записи сообщества{{/?}}{{/:widget_title}}

{{:items}}

	{{?widget.content.ftype == "fimage"}}
		{{!for items as="data" do=@:item_one}}{{:item_one}}
			{{?data.type == "fimage"}}
			<li class="item-"><a href="{{/}}{{data.community.community_url}}/{{data.id}}"><img src="{{!thumb data.image.path_to_orig filter='smart' w=55 h=55}}" class="img-" /></a></li>
			{{/?}}
		{{/:item_one}}
	{{?:widget.content.ftype == "ffile"}}
		{{!for items as="data" do=@:item_file}}{{:item_file}}
			{{?data.type == "ffile"}}
				<li class="item-"><a href="{{/}}filestorage/{{data.file_oid}}" title="{{*file_meta.real_fname}}">{{data.file.real_fname | truncate 19}}</a>&nbsp;{{data.file.file_size|formatfilesize}}</li>
			{{/?}}
		{{/:item_file}}
	{{?:}}
		<div class="date-">{{items.0.date}}</div>
		<div class="list-titles-">
		{{!for items as="data" do=@:widget_item}}{{:widget_item}}
			<div class="item-">
				<span class="subheader-">&laquo;<a href="{{/}}{{data.community.community_url}}/{{data.id}}">{{data.title}}</a>&raquo;</span>
				{{?data.user.oid}}
				<div class="author-">
					<div class="avatar-"><a href="{{/}}members/{{data.user.oid}}"><img src="{{?data.user.avatar}}{{/}}{{data.user.avatar | link_to 'imagestorage' 'sm2'}}{{?:}}{{images}}avatar-22x22.png{{/?}}" alt="" class="bn" /></a></div>
					<a href="{{/}}members/{{data.user.oid}}" class="username-">{{data.user.fullname}}</a>
				</div>
				{{/?}}
				<span class="time-">в {{data.ctime}},</span>
				{{?data.comments_count}}
					<a href="{{/}}{{data.community.community_url}}/{{data.id}}?showcomments#comments" class="comments- commments-count-">{{!plural data.comments_count "комментари" "й" "я" "ев"}}</a>.
				{{?:}}
					<span class="comments- comments-none-">комментариев пока нет.</span>
				{{/?}}
			</div>
		{{/:widget_item}}
		</div>
	{{/?}}
	
{{/:items}}


{{:settings}}
<div class="popup-widgets" id="settings_container">
	<form action="" id="settingsform">
	<input type="hidden" name="widget_id" value="{{settings.id}}" id="widget_id" />
	<h2 class="title-">Последние сообщения</h2>
	<div class="content-" style="height: 400px; overflow: auto;">
		<fieldset class="fieldset- header- text-">
			<label>Заголовок</label>
			<input type="text" name="title" value="{{settings.title}}" />
			<div class="comment-">Не более 100 символов</div>
		</fieldset>
		<fieldset class="fieldset- header- text-">
			<label>Количество сообщений</label>
			<input type="text" name="itemscount" value="{{settings.itemscount}}" />
		</fieldset>
		<fieldset class="fieldset- header- text-">
			<label>Тип сообщений</label>
			<select name="ftype">
				<option value="all"{{?settings.ftype == "all"}} selected="selected"{{/?}}>Вся лента</option>
				<option value="fdoc"{{?settings.ftype == "fdoc"}} selected="selected"{{/?}}>Сообщения</option>
				<option value="fimage"{{?settings.ftype == "fimage"}} selected="selected"{{/?}}>Картинки</option>
				<option value="ffile"{{?settings.ftype == "ffile"}} selected="selected"{{/?}}>Файлы</option>
			</select>
		</fieldset>
		<fieldset class="fieldset- header- text-">
			<label>Сообщения:</label>
			<input type="radio" style="display:inline;width: 24px;" id="from_node" name="from" value="node"{{?'node'==settings.from || !settings.from}} checked="checked"{{/?}} />
			<label for="from_node" style="display:inline; margin-left: 24px;"> всего узла</label><br />
			<input type="radio" style="display:inline;width: 24px;" id="from_community" name="from" value="community"{{?'community'==settings.from}} checked="checked"{{/?}} /> 
			<label for="from_community" style="display:inline; margin-left: 24px;">только из сообществ</label><br />
			{{!for settings.community do=@:community}}
		</fieldset>
	</div>
	{{@:settingsbutton}}
	</form>
	<script>
	jQuery("#from_node").bind("click", function(){
		setCheckBoxRights()
	});
	jQuery("#from_community").bind("click", function(){
		setCheckBoxRights()
	});
	jQuery().ready( function(){
		setCheckBoxRights();
	});
	
	function setCheckBoxRights() {
		var from_node = jQuery("#from_node").get(0).checked;
		jQuery("#settings_container").find("input.commcheck-").each(function(){
			if ( from_node ) {
				this.disabled = true;
				this.checked = false;
			} else {
				this.disabled = false;
			}
		});
	}
	
	function toggleGroup( parentItem, groupName ) {
		var setCheck = parentItem.checked;
		jQuery("#settings_container").find("input." + groupName).each(function(){
			this.checked = setCheck;
		});
	}
	
	function testCheckParent( childItem, parentOID, groupName ) {
		var setCheck = childItem.checked;
		
		if ( setCheck ) {
			jQuery("#community" + parentOID).get(0).checked = true;
		} else {
			var needClean = true;
			jQuery("#settings_container").find("input." + groupName).each(function(){
				if ( this.checked ) {
					needClean = false;
				}
			});
			
			if ( needClean ) {
				jQuery("#community" + parentOID).get(0).checked = false;
			}
		}
	}
	</script>
</div>
{{/:settings}}
